﻿using System;
using System.Web.UI.WebControls;
using ATSBLL;

public partial class TestViewbyProduct_SNDateCategory : System.Web.UI.Page
{
     private TTest test;

     public TestViewbyProduct_SNDateCategory()
    {
        test = new TTest();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        
    } 

    public void BindTests()
    {

       
        string UserId = this.TextBox3.Text.Trim();
        string UserId2 = this.TextBox4.Text.Trim();
        DateTime dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        DateTime dt2 = DateTime.Parse(this.TextBox2.Value.Trim());

        this.GridView1.DataSource = test.GetTestsbyUIDDT(UserId, UserId2, dt1, dt2);
        
        GridView1.DataBind();
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.Rows[i].Cells[8].Text == "Fail")
                GridView1.Rows[i].Cells[8].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        BindTests();
    }
    
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindTests();
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GridView1.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GridView1.SelectedDataKey["RecordTime"]);
        Session["ProductTypeID"] = GridView1.SelectedDataKey["ProductTypeID"].ToString();
        Session["UserID"] = GridView1.SelectedDataKey["UserID"].ToString();
        if ((GridView1.SelectedDataKey["UserID2"]) == null)
            Session["UserID2"] = Convert.ToBoolean(GridView1.SelectedDataKey["UserID2"]) ? null : "";
        else Session["UserID2"] = GridView1.SelectedDataKey["UserID2"].ToString();
        
        Session["ENAID"] = GridView1.SelectedDataKey["ENAID"].ToString();
        Session["IsPass"] = GridView1.SelectedDataKey["IsPass"].ToString();

        Response.Redirect("~/TestViewbyProduct/TestDetails/ViewTTestItem.aspx");
      
    }
}
